package user.servlet;

import user.entity.Administrator;
import user.service.AdministratorService;
import user.service.impl.AdministratorServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        String Email=request.getParameter("email");
        String password=request.getParameter("password");

        AdministratorService service=new AdministratorServiceImpl();
        Administrator a=new Administrator();
        a.setEmail(Email);
        a.setCipher(password);
        int count=service.UpdateInfo(a);
        PrintWriter out=response.getWriter();
        if (count>0){
            out.print("<script>");
            out.print("alert(\"修改成功!\");");
            out.print("location.href=\"user.jsp\";");
            out.print("</script>");
        }else {
            out.print("<script>");
            out.print("alert(\"修改失败!\");");
            out.print("location.href=\"wjmm.jsp\";");
            out.print("</script>");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
